
import _ from 'lodash';
export var websock = {};
var msgQueue = [];
let wsuri

export function initWebSocket(address) { //初始化weosocket
    if(websock.readyState==1||websock.readyState==0){
        return false
    }
    websock = new WebSocket(address)
    return true
    //ws地址
    let hostname = window.location.hostname
    let wsHost = localStorage.getItem('wsHost')
    if(hostname.indexOf('localhost')!=-1||hostname.indexOf('192')!=-1){
        //本地
        wsuri = "wss://www.appbale.net:7272";
    }else{
        wsuri = "wss://"+hostname+':'+wsHost;        
    }
    if(hostname.indexOf('www.')!=-1){
        hostname=hostname.substring(4)
    }
    setWsUrl(hostname)
    websock = new WebSocket(wsuri);
    // websock = new WebSocket('wss://wss.100.com:7272');
};

function setWsUrl(hostname){
    if(hostname=='dandanaa.com'){//预演
        wsuri = "wss://www.dandanaa.com:7272";        
    }else if(hostname=='dandanbb.com'){
        wsuri = "wss://www.dandanbb.com:7272";        
    }

    if (hostname=='tuiqiu55.com') { //tuiqiu55
        wsuri = "wss://tuiqiu55.com:7272";        
    } else if (hostname=='www.tuiqiu55.com') {
        wsuri = "wss://www.tuiqiu55.com:7272";        
    }

    if (hostname=='tuiqiu66.com') { //tuiqiu66
        wsuri = "wss://tuiqiu66.com:7273";        
    } else if (hostname=='www.tuiqiu66.com') {
        wsuri = "wss://www.tuiqiu66.com:7273";        
    }

    if(hostname=='leyinga.com'||hostname=='leyingb.com'||hostname=='leyingc.com'){//乐盈
        wsuri = "wss://wss.leyinga.com:7272";        
    }else if(hostname=='leyinge.com'||hostname=='leyingf.com'||hostname=='leyingg.com'||hostname=='leyingd.com'){
        wsuri = "wss://"+hostname+':7293';
    }
    if(hostname=='11pc87.com'||hostname=='44pc87.com'||hostname=='22pc87.com'||hostname=='55pc87.com'||hostname=='33pc87.com'){//乐享
        wsuri = "wss://wss.11pc87.com:7272";
    }else if(hostname=='66pc87.com'||hostname=='00pc87.com'||hostname=='77pc87.com'||hostname=='88pc87.com'||hostname=='99pc87.com'){
        wsuri = "wss://"+hostname+':7294';
    }
    if(hostname=='www-yb55.com'||hostname=='ybgj69.com'||hostname=='yb55.com'||hostname=='www.yb55.com'||hostname=='yb6989.com'||hostname=='www.yb6989.com'){//元宝国籍
        wsuri = "wss://wss.www-yb55.com:7272";
    }else if(hostname=='yb55vip.com'||hostname=='ybgj123.com'||hostname=='yb789.com'||hostname=='www-yb789.com'){
        wsuri = "wss://"+hostname+':7296';
    }
    if(hostname=='500cc1.com'||hostname=='500cc8.com'||hostname=='500cc4.com'||hostname=='500cc3.com'||hostname=='500cc2.com'){//500w
        wsuri = "wss://500cc9.com:7272";
    }else if(hostname=='500cc7.com'||hostname=='500cc6.com'||hostname=='500cc5.com'||hostname=='500cc11.com'||hostname=='500cc111.com'||hostname=='500cc22.com'||hostname=='500cc222.com'||hostname=='500cc33.com'||hostname=='500cc333.com'||hostname=='500cc44.com'||hostname=='500cc444.com'||hostname=='500cc55.com'||hostname=="500cc555.com"||hostname=="500cc66.com"||hostname=="500cc666.com"||hostname=="500cc77.com"||hostname=="500cc777.com"||hostname=="500cc88.com"){
        wsuri = "wss://"+hostname+':7280';
    }
    if(hostname=='cp60658.com'||hostname=='pc60658.com'||hostname=='dd60658.com'||hostname=='1ww-pc5858.com'||hostname=='www.1ww-pc5858.com'||hostname=='pc8989.com'||hostname=='www.pc8989.com'||hostname=='www-pc4444.com'||hostname=='www.www-pc4444.com'||hostname=='www-pc5555.com'||hostname=='www.www-pc5555.com'||hostname=='www-pc5858.com'||hostname=='www.www-pc5858.com'||hostname=='pc4444.com'||hostname=='www.pc4444.com'||hostname=='pc5858.com'||hostname=='www.pc5858.com'||hostname=='60658.com'||hostname=='www.60658.com'){//PC国际
        wsuri = "wss://www.4ww-pc5858.com:7272";
    }else if(hostname=='2ww-pc5858.com'||hostname=='www.2ww-pc5858.com'||hostname=='3ww-pc5858.com'||hostname=='www.3ww-pc5858.com'||hostname=='5ww-pc5858.com'||hostname=='www.5ww-pc5858.com'||hostname=='6ww-pc5858.com'||hostname=='www.6ww-pc5858.com'||hostname=='7ww-pc5858.com'||hostname=='www.7ww-pc5858.com'||hostname=='8ww-pc5858.com'||hostname=='www.8ww-pc5858.com'||hostname=="9ww-pc5858.com"||hostname=="www.9ww-pc5858.com"||hostname=="pc9898.com"||hostname=="www.pc9898.com"||hostname=="pc5555.com"||hostname=="www.pc5555.com"||hostname=="4ww-pc5858.com"||hostname=="www.4ww-pc5858.com"||hostname=="www-60658.com"||hostname=="www.www-60658.com"){
        wsuri = "wss://"+hostname+':7281';
    }
    if(hostname=='cb722.com'||hostname=='appcb7.com'||hostname=='cb722.com'){//彩吧
        wsuri = "wss://wss.cb722.com:7272";
    }else if(hostname=='2019cb.com'||hostname=='cb733.com'||hostname=='cb744.com'){
        wsuri = "wss://"+hostname+':7290';
    }
    //王者集团
    if(hostname=='wzjt28.com'||hostname=='wzjt18.com'||hostname=='wzjt58.com'||hostname=='wzjt38.com'||hostname=='wzjt88.com'||hostname=='wzjt78.com'||hostname=='wzjt68.com'){
        wsuri = "wss://"+hostname+':7291';
    }
    if(hostname=='jbp285.com'||hostname=='28jbp.com'||hostname=='jbp281.com'||hostname=='jbp282.com'||hostname=='jbp283.com'){//聚宝盆
        wsuri = "wss://wss.jbp285.com:7272";
    }else if(hostname=='jbp280.com'||hostname=='jbp284.com'||hostname=='28jbp.net'||hostname=='jbp286.com'){
        wsuri = "wss://"+hostname+':7289';
    }
    if(hostname=='www-pc59.com'||hostname=='pc59.app'||hostname=='gcai99.com'||hostname=='gcai55.com'||hostname=='gcai56.com'||hostname=='pc6688.com'||hostname=='www.pc6688.com'||hostname=='pc6699.com'||hostname=='www.pc6699.com'){//佰亿
        wsuri = "wss://wss.www-pc59.com:7272";
    }else if(hostname=='pc3399.com'||hostname=='pc2299.com'||hostname=='ww-pc59.com'||hostname=='gcai44.com'||hostname=='gcai57.com'||hostname=='gcai58.com'||hostname=='pc5588.com'||hostname=='pc5599.com'||hostname=='wwpc59.com'){
        wsuri = "wss://"+hostname+':7295';
    }
    if(hostname=='wwwpc222.com'||hostname=='app.df123456.com'||hostname=='pc222.com'||hostname=='df933.com'||hostname=='df998.com'||hostname=='df899.com'||hostname=='pc28.tw'){//大发28
        wsuri = "wss://www-pc222.com:7272";
    }else if(hostname=='df4567.com'||hostname=='df977.com'||hostname=='df7788.com'||hostname=='df933.com'||hostname=='df955.com'||hostname=='df966.com'||hostname=='pc5959.com'||hostname=='pcpc28.com'||hostname=='wwwpc28.tw'){
        wsuri = "wss://"+hostname+':7288';
    }
    if(hostname=='www-pc520.com'||hostname=='pc2817.com'||hostname=='legou28.com'||hostname=='pc6070.com'){//乐购
        wsuri = "wss://wss.www-pc520.com:7272";
    }else if(hostname=='pc6070.com'||hostname=='lg2818.com'||hostname=='pc7028.com'||hostname=='pc990.com'){
        wsuri = "wss://"+hostname+':7282';
    }
    if(hostname=='ttsy369.com'||hostname=='app.df123456.com'||hostname=='ttsy689.com'||hostname=='ttsy678.com'||hostname=='ttsy0.com'||hostname=='ttsy1.com'||hostname=='ttsy2.com'){//天天手游nmsl!!!
        wsuri = "wss://ttsy-579656688.com:7272";
    }else if(hostname=='ttsy678.com'||hostname=='ttsy2222.com'||hostname=='ttsy00.com'||hostname=='ttsy000.com'||hostname=='ttsy0000.com'||hostname=='ttsy11.com'||hostname=='ttsy111.com'||hostname=='ttsy1111.com'||hostname=='ttsy22.com'||hostname=='ttsy222.com'||hostname=='ttsy3.com'||hostname=='ttsy33.com'||hostname=='ttsy333.com'||hostname=='ttsy3333.com'||hostname=='ttsy369.com'||hostname=='ttsy4.com'||hostname=='ttsy44.com'||hostname=='ttsy444.com'||hostname=='ttsy4444.com'||hostname=='ttsy5.com'||hostname=='ttsy55.com'||hostname=='ttsy555.com'||hostname=='ttsy5555.com'||hostname=='ttsy578.com'||hostname=='ttsy588.com'||hostname=='ttsy66.com'||hostname=='ttsy666.com'||hostname=='ttsy6666.com'||hostname=='ttsy668.com'||hostname=='ttsy77.com'||hostname=='ttsy777.com'||hostname=='ttsy7777.com'||hostname=='ttsy789.com'||hostname=='ttsy858.com'||hostname=='ttsy888.com'||hostname=='ttsy8888.com'||hostname=='ttsy899.com'||hostname=='ttsy8a.com'||hostname=='ttsy8b.com'||hostname=='ttsy8c.com'||hostname=='ttsy8d.com'||hostname=='ttsy8e.com'||hostname=='ttsy8f.com'||hostname=='ttsy8g.com'||hostname=='ttsy8h.com'||hostname=='ttsy8i.com'||hostname=='ttsy8j.com'||hostname=='ttsy8k.com'||hostname=='ttsy8l.com'||hostname=='ttsy8m.com'||hostname=='ttsy8n.com'||hostname=='ttsy8o.com'||hostname=='ttsy8p.com'||hostname=='ttsy8q.com'||hostname=='ttsy8r.com'||hostname=='ttsy8s.com'||hostname=='ttsy8t.com'||hostname=='ttsy8u.com'||hostname=='ttsy8v.com'||hostname=='ttsy8w.com'||hostname=='ttsy8x.com'||hostname=='ttsy8y.com'||hostname=='ttsy8z.com'||hostname=='ttsy9.com'||hostname=='ttsy99.com'||hostname=='ttsy999.com'||hostname=='ttsy9999.com'){
        wsuri = "wss://"+hostname+':7292';
    }
    if(hostname=='www-pc77.com'||hostname=='www-pc28.tt'||hostname=='pc444.com'||hostname=='pc7177.com'||hostname=='pc7277.com'||hostname=='pc28.xxx'){//王者28
        wsuri = "wss://www.33pc00.com:7272";
    }else if(hostname=='pc28.world'||hostname=='33pc11.com'||hostname=='pc28.tt'||hostname=='pc567.com'||hostname=='pc77.com'||hostname=='www-pc567.com'||hostname=='www-pc77.com'||hostname=='pc7377.com'||hostname=='pc7477.com'||hostname=='pc7377.com'||hostname=='pc7477.com'||hostname=='pc7577.com'||hostname=='pc7677.com'||hostname=='pc7777.com'||hostname=='pc7877.com'||hostname=='pc7977.com'||hostname=='33pc22.com'||hostname=='33pc33.com'||hostname=='33pc44.com'||hostname=='33pc55.com'||hostname=='33pc66.com'||hostname=='33pc77.com'||hostname=='33pc88.com'||hostname=='33pc99.com'){
        wsuri = "wss://"+hostname+':7272';
    }
    if(hostname=='pc9628.com'||hostname=='pcdd.cx'||hostname=='pc28.cx'){//诚信28
        wsuri = "wss://wss.pc9628.com:7272";
    }else if(hostname=='pc9828.com'||hostname=='pc28cx.com'||hostname=='pcddcx.com'||hostname=='www.pcddcx.com'){
        wsuri = "wss://"+hostname+':7283';
    }
    if(hostname=='112828cp.com'||hostname=='112828.com'||hostname=='1ww-pc3333.com'||hostname=='ylc6699.com'||hostname=='ylc6969.com'||hostname=='www-pc3333.com'||hostname=='pcdd6969.com'||hostname=='pc9696.com'){//畅赢
        wsuri = "wss://www.4ww-pc3333.com:7272";
    }else if(hostname=='www.pc3333.com'||hostname=='www.112828cp.com'||hostname=='2ww-pc3333.com'||hostname=='3ww-pc3333.com'||hostname=='pc3333.com'||hostname=='pcdd0027.com'||hostname=='pcdd9696.com'||hostname=='5ww-pc3333.com'||hostname=='6ww-pc3333.com'||hostname=='7ww-pc3333.com'||hostname=='8ww-pc3333.com'||hostname=='9ww-pc3333.com'){
        wsuri = "wss://"+hostname+':7285';
    }
    if(hostname=='pc868.com'||hostname=='pc3457.com'||hostname=='pc577.com'||hostname=='juke11.com'||hostname=='juke66.com'||hostname=='jk876.com'){//聚客手游
        wsuri = "wss://pc868.org:7272";
    }else if(hostname=='pc299.com'||hostname=='jk987.com'||hostname=='pc599.com'||hostname=='pc917.com'||hostname=='pc366.com'||hostname=='juke44.com'||hostname=='juke77.com'||hostname=='juke22.com'||hostname=='juke33.com'||hostname=='juke55.com'||hostname=='juke9.com'||hostname=='juke7.com'||hostname=='juke4.com'||hostname=='juke5.com'||hostname=='juke6.com'||hostname=='juke2.com'||hostname=='juke1.com'||hostname=='juke883.com'||hostname=='juke885.com'||hostname=='pc868.cc'){
        wsuri = "wss://"+hostname+':7287';
    }
    if(hostname=='sfcp100.com'||hostname=='sfcp101.com'||hostname=='www.sfcp100.com'||hostname=='sfcp106.com'||hostname=='www.sfcp106.com'){//顺发
        wsuri = "wss://wss.sfcp100.com:7272";
    }else if(hostname=='sfcp105.com'||hostname=='sfcp107.com'||hostname=='sfcp108.com'||hostname=='sfcp109.com'||hostname=='sfcp110.com'){
        wsuri = "wss://"+hostname+':7297';
    }
    if(hostname=='dlt000.com'||hostname=='dltvip.net'||hostname=='888dlt.com'||hostname=='111dlt.com'||hostname=='dlt011.com'){//大乐透
        wsuri = "wss://wss.dlt000.com:7272";
    }else if(hostname=='222dlt.com'||hostname=='app.dltapp.vip'||hostname=='dltvip.vip'||hostname=='dlt022.com'||hostname=='dlt033.com'||hostname=='dlt044.com'||hostname=='dlt055.com'||hostname=='dlt066.com'||hostname=='dlt077.com'||hostname=='dlt099.com'||hostname=='000dlt.com'||hostname=='333dlt.com'||hostname=='444dlt.com'||hostname=='555dlt.com'||hostname=='666dlt.com'||hostname=='777dlt.com'||hostname=='999dlt.com'){
        wsuri = "wss://"+hostname+':7298';
    }
    if(hostname=='bbc333.com'){//百盈
        wsuri = "wss://www.bbc333.com:7272";
    }else if(hostname=='hmbhightech.com'||hostname=='bbc444.com'){
        wsuri = "wss://"+hostname+':7272';
    }

    if (hostname=='lb2821.com' || hostname=='lb2822.com' || hostname=='lb28.cc' || hostname=='www.lb2821.com' || hostname=='www.lb2822.com' || hostname=='www.lb28.cc') { //乐博28
        wsuri = "wss://wss.lb2821.com:7272";
    } else if (hostname=='lb2823.com' || hostname=='lb2824.com' || hostname=='lb2825.com' || hostname=='lb2826.com' || hostname=='lb2827.com' || hostname=='lb2828.com' || hostname=='lb2829.com' || hostname=='lb28.com') {
        wsuri = "wss://"+hostname+':7299';
    }
}
export function threadPoxi() { // 心跳连接
    const agentData = { "commandid": "3012", "uid": JSON.parse(localStorage.getItem("userData")).uid };
    websocketsend(agentData);
    var xintiao = setInterval(function() {
        websocketsend(agentData);
    }, 30000);
    websock.addEventListener("close", function(event){
        clearInterval(xintiao);
    });
}
// function websocketonmessage(e){ //数据接收
//       if(websock.readyState===1){
//         console.log('返回数据:'+JSON.stringify(e.data));
//         return e.data;
//       }
//   };
export function websocketsend(agentData) { //数据发送
    msgQueue.unshift(agentData);

    // WebSocket处于OPEN的状态时,将消息队列中的消息逐个取出来发送
    if (websock.readyState === 1) {
        for (var i = 0; i < msgQueue.length; i++) {
            var msg = msgQueue.pop();
            var _msg = JSON.stringify(msg);
            console.log("发送的消息为：" + _msg);
            websock.send(_msg);
        }
    }
};
export default {
    websock,
    initWebSocket,
    threadPoxi,
    websocketsend,
}


// WEBPACK FOOTER //
// ./src/common/js/websocket.js